﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Entity.ProjectEnt;
using ZFine.Application.Project;
using ZFine.Code;
using ZFine.Domain.Entity;
using ZFine.Web;

namespace Logiv.WEB.Areas.Project.Controllers
{
    public class PositionRecordController:BaseController
    {
        private PositionRecordApp serverApp = new PositionRecordApp();
        public ActionResult Index()
        {
            return View();
        }


        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string keyValue)
        {
            try
            {
                //将url解码
                //Encoding utf8 = Encoding.UTF8;
                //string code = HttpUtility.UrlDecode(keyValue.ToUpper(), utf8);

                var reuslt = serverApp.GetList(pagination);
                var result = (from num in reuslt
                              select new PositionRecordEntity
                              {
                                  F_Id = num.F_Id,
                                  BanciUser=num.BanciUser,
                                  F_CreatorTime=num.F_CreatorTime,
                                  State=num.State,
                                  CreateAdmin = num.CreateAdmin == null ? null : new UserEntity()
                                  {
                                      F_Id=num.CreateAdmin.F_Id,
                                      F_RealName=num.CreateAdmin.F_RealName
                                  },
                                  DispatcherUser = num.DispatcherUser == null ? null : new UserEntity()
                                  {
                                      F_Id = num.DispatcherUser.F_Id,
                                      F_RealName = num.DispatcherUser.F_RealName
                                  },
                                  DiaochezhangUser = num.DiaochezhangUser == null ? null : new UserEntity()
                                  {
                                      F_Id = num.DiaochezhangUser.F_Id,
                                      F_RealName = num.DiaochezhangUser.F_RealName
                                  },
                                  TougouyuanUser = num.TougouyuanUser == null ? null : new UserEntity()
                                  {
                                      F_Id = num.TougouyuanUser.F_Id,
                                      F_RealName = num.TougouyuanUser.F_RealName
                                  },
                                  ZhongzhuanyuanUser = num.ZhongzhuanyuanUser == null ? null : new UserEntity()
                                  {
                                      F_Id = num.ZhongzhuanyuanUser.F_Id,
                                      F_RealName = num.ZhongzhuanyuanUser.F_RealName
                                  },
                                  SijiUser = num.SijiUser == null ? null : new UserEntity()
                                  {
                                      F_Id = num.SijiUser.F_Id,
                                      F_RealName = num.SijiUser.F_RealName
                                  },
                                  FusijiUser = num.FusijiUser == null ? null : new UserEntity()
                                  {
                                      F_Id = num.FusijiUser.F_Id,
                                      F_RealName = num.FusijiUser.F_RealName
                                  },
                                  HuoyunyunaUser1 = num.HuoyunyunaUser1 == null ? null : new UserEntity()
                                  {
                                      F_Id = num.HuoyunyunaUser1.F_Id,
                                      F_RealName = num.HuoyunyunaUser1.F_RealName
                                  },
                                  HuoyunyunaUser2 = num.HuoyunyunaUser2 == null ? null : new UserEntity()
                                  {
                                      F_Id = num.HuoyunyunaUser2.F_Id,
                                      F_RealName = num.HuoyunyunaUser2.F_RealName
                                  },
                                  daokouyuanUser1 = num.daokouyuanUser1 == null ? null : new UserEntity()
                                  {
                                      F_Id = num.daokouyuanUser1.F_Id,
                                      F_RealName = num.daokouyuanUser1.F_RealName
                                  },
                                  daokouyuanUser2 = num.daokouyuanUser2 == null ? null : new UserEntity()
                                  {
                                      F_Id = num.daokouyuanUser2.F_Id,
                                      F_RealName = num.daokouyuanUser2.F_RealName
                                  },
                              }).ToList();
                var data = new
                {
                    rows = result,
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());

            }
            catch (Exception ex)
            {
                return null;
            }

        }

    }
}